//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.neurosky.thinkgear;

import com.neurosky.thinkgear.SGFilter;
import com.neurosky.thinkgear.TGBlinkDetector;
import java.util.ArrayList;
import java.util.List;

public class BlinkFilter {
    private TGBlinkDetector a = new TGBlinkDetector();
    private SGFilter b = new SGFilter();
    private List c = new ArrayList();
    private int d;
    private int e;
    private int f;
    private int g;
    private int h;
    private float[] i;
    private float j;
    private int k;
    private float[] l;
    private float[] m;
    private int n;

    public BlinkFilter(int var1) {
        this.d = var1;
    }

    public float[] filter(byte var1, float[] var2) {
        this.l = new float[var2.length];
        System.arraycopy(var2, 0, this.l, 0, var2.length);
        this.n = 0;
        this.c.clear();
        this.a.Detect(200, (short)200);

        int var3;
        for(var3 = 0; var3 < var2.length; ++var3) {
            if(this.a.Detect(var1, (short)((int)var2[var3])) != 0) {
                if(this.a.blinkStart < this.a.blinkEnd) {
                    if(this.n - (this.a.blinkEnd - this.a.blinkStart - 1) < 0) {
                        this.c.add(Integer.valueOf(0));
                    } else {
                        this.c.add(Integer.valueOf(this.n - (this.a.blinkEnd - this.a.blinkStart - 1)));
                    }

                    this.c.add(Integer.valueOf(this.n));
                } else {
                    this.c.add(Integer.valueOf(this.n - (this.a.blinkStart + (512 - this.a.blinkEnd))));
                    this.c.add(Integer.valueOf(this.n));
                }
            }

            ++this.n;
        }

        for(var3 = 0; var3 < this.c.size() / 2; ++var3) {
            this.e = ((Integer)this.c.get(var3 << 1)).intValue();
            this.f = ((Integer)this.c.get((var3 << 1) + 1)).intValue();
            this.h = 5;
            this.g = 61 * (this.d / 256);
            if(this.g % 2 == 0) {
                ++this.g;
            }

            if(this.f - this.e < this.g) {
                this.j = (float)((this.f - this.e) / 2);
                if((float)((int)this.j) > this.j) {
                    this.j = (float)((int)this.j - 1);
                } else if((float)((int)this.j) < this.j) {
                    this.j = (float)((int)this.j);
                }

                this.g = ((int)this.j << 1) + 1;
            }

            if(this.g <= this.h) {
                this.h = this.g - 1;
            }

            if(this.e != 0 && this.f != 0) {
                this.k = this.f - this.e + 1;
            } else {
                this.k = this.f - this.e + 2;
            }

            this.i = new float[this.k];
            if(this.e > 0 && this.f < var2.length - 1) {
                this.i = a(var2[this.e - 1], var2[this.f + 1], this.k);
            } else if(this.e == 0 && this.f < var2.length - 1) {
                this.i = a(var2[this.e], var2[this.f + 1], this.k);
            } else if(this.e > 0 && this.f == var2.length - 1) {
                this.i = a(var2[this.e - 1], var2[this.f], this.k);
            } else {
                this.i = a(var2[this.e], var2[this.f], this.k);
            }

            if(this.g % 2 == 0) {
                ++this.g;
            }

            this.m = new float[this.k];
            System.arraycopy(var2, this.e, this.m, 0, this.k);
            this.m = this.b.filterData(this.m, this.g, this.h);

            for(int var4 = 0; var4 < this.m.length; ++var4) {
                this.l[this.e + var4] = var2[this.e + var4] - this.m[var4] + this.i[var4];
            }
        }

        return this.l;
    }

    private static float[] a(float var0, float var1, int var2) {
        float[] var3 = new float[var2];
        var1 = (var1 - var0) / (float)(var2 - 1);
        var3[0] = var0;

        for(int var4 = 1; var4 < var2; ++var4) {
            var3[var4] = var3[var4 - 1] + var1;
        }

        return var3;
    }
}
